<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //Promise是异步操作的一种解决方案

        //层层嵌套：回调地狱
        //Promise：解决回调地狱的问题

        //实例化构造函数生成实例对象
        console.log(Promise)

        const p = new Promise((resolve, reject) => {
            //Promise有三种状态，一是开始pending(未完成)
            //执行 resolve变成fulfilled( resolved)已成功
            //执行reject变成reject 已失败
            //Promise的状态一旦变化了 就不会再改变了
            //pending=>fulfilled( resolved)已成功
            resolve({
                username: 'li'
            });

            //pending=>rejected已失败
            //  reject();

        })

        //then方法
        p.then((data) => {
            console.log('success', data);
        }, () => {
            console.log('error');
        })

        console.log(p);
    </script>
</body>

</html>